import useAuthButtons from "@/hooks/useAuthButtons";
import { ButtonProps } from "antd";
import React from "react";

type ButtonComponent = React.FC<ButtonProps> | JSX.Element | null;
interface ButtonPerProps {
    btn: string,
    Comp: ButtonComponent
}

function ButtonPer ({btn, Comp}: ButtonPerProps): JSX.Element | null {
    const {BUTTONS} = useAuthButtons()
    // 如果btn为空，返回Comp
    if (!btn) {
        return <>{Comp}</>
    }
    // 判断Buttons是否是空对象
    if (Object.keys(BUTTONS).length === 0) {
        return null
    }
    if (BUTTONS && BUTTONS.includes(btn) && Comp) {
        // 包裹在React.Fragment中以确保返回一个JSX.Element
        return <>{Comp}</>
    } 
    return null
}

export default ButtonPer;